def nodeNames = params.NODE_NAMES
def allNodes = nodeNames.split("\n")
allNodes.each { n ->
    println n
    def nodeNameAndIP = n.split("-")
    def nodeName = nodeNameAndIP[0]
    def ip = nodeNameAndIP[1]
    println "正在节点[${nodeName}]上部署filehandler"
    node(nodeName) {
        stage('deploy') {
            sh "docker pull registry-intl.cn-hangzhou.aliyuncs.com/xkw-rbm/xkw-rbm-file-handler-webapp:1.0.1"
            result1 = sh returnStatus: true ,script: "docker stop file-handler"
            println "stop container: $result1"
            result2 = sh returnStatus: true ,script: "docker rm file-handler"
            println "rm container: $result2"

            withEnv(['JENKINS_NODE_COOKIE=dontkillme']) {
                sh "docker run -d --name file-handler " +
                        "-e SPRING_OPTS='--spring.profiles.active=${params.PROFILE} --spring.cloud.nacos.discovery.ip=${ip} --spring.cloud.nacos.discovery.port=8096'" +
                        " -v /data/logs/rbm-file-handler:/data/logs/rbm-file-handler " +
                        "-v /data/tmp:/tmp " +
                        "-p 8096:8086 registry-intl.cn-hangzhou.aliyuncs.com/xkw-rbm/xkw-rbm-file-handler-webapp:1.0.1"
            }
        }
    }
}
println(allNodes)
//println "nodeName: ${nodeName}"

//node(nodeName) {
//
//    stage('deploy') {
//        sh "docker pull registry-intl.cn-hangzhou.aliyuncs.com/xkw-rbm/xkw-rbm-file-handler-webapp:1.0.1"
//        result1 = sh returnStatus: true ,script: "docker stop file-handler"
//        println "stop container: $result1"
//        result2 = sh returnStatus: true ,script: "docker rm file-handler"
//        println "rm container: $result2"
//        sh "docker run -d --name file-handler \\\n" +
//                "-e SPRING_OPTS='--spring.profiles.active=product --spring.cloud.nacos.discovery.ip=10.1.23.159 --spring.cloud.nacos.discovery.port=8096' \\\n" +
//                "-v /data/logs/rbm-file-handler:/data/logs/rbm-file-handler \\\n" +
//                "-v /data/tmp:/tmp \\\n" +
//                "-p 8096:8086 \\\n" +
//                "registry-intl.cn-hangzhou.aliyuncs.com/xkw-rbm/xkw-rbm-file-handler-webapp:1.0.1"
//    }
//}